import java.lang.reflect.Array;
import java.util.*;

public class Main {



    //删除相邻数字的最大分数
    public static long maxPoints(int[] nums){
        Map<Integer,Long> count = new HashMap<>();
        int maxNum = 0;
        for (int num:nums) {
            count.put(num,count.getOrDefault(num,0L)+1);
            maxNum = Math.max(maxNum,num);
        }
        long[] dp = new long[maxNum+2];
        dp[1] = count.getOrDefault(1,0L);

        for (int i = 2; i <= maxNum; i++) {
            dp[i] = Math.max(dp[i-1],dp[i-2]+i*count.getOrDefault(i,0L));
        }
        return dp[maxNum];
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        System.out.println(maxPoints(nums));
        in.close();
    }








    //组队竞赛
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()){
            int n = in.nextInt();
            int[] array = new int[3*n];
            for (int i = 0; i < array.length; i++) {
                array[i] = in.nextInt();

            }
            Arrays.sort(array);
            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += array[array.length-(2*(i+1))];
            }
            System.out.println(sum);
        }
    }











    //乒乓球筐
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            boolean contain = true;
            StringBuffer s = new StringBuffer(in.next());
            char[] find = in.next().toCharArray();
            for (char c:find) {
                int index = s.indexOf(String.valueOf(c));
                if(index != -1) s.deleteCharAt(index);
                else{
                    System.out.println("No");
                    contain = false;
                    break;
                }
            }
            if (contain) System.out.println("Yes");
        }
    }








}
